<template>
  <div
    v-loading="loading"
    element-loading-text="拼命加载中"
    element-loading-spinner="el-icon-loading"
    element-loading-background="rgba(0, 0, 0, 0.8)">
    <!--搜索栏-->
    <common-list-search-bar
      v-if="!this.isDialogShow()"
      ref="commonListSearchBar"
      :field-arr="searchSittingArray"
      :search-list="searchList">

    </common-list-search-bar>
    <common-list-table
      ref="myCommonListTable"
      :sitting="listTableSitting"
      :search-list="searchList">
    </common-list-table>
  </div>
</template>

<script>

import CreateProductDialog from '../Dialog/CreateProductDialog'
import CreateStockDialog from '../Dialog/CreateStockDialog'

export default {
  name: 'ProductLogPage',
  components: {CreateStockDialog, },
  props:{
    productData:Object,
  },
  mounted () {
    // 模拟数据
    // this.$refs.myCommonListTable.setListData(DemoData.Product.list)
    this.searchList()
  },
  data:function () {
    return {
      loading:false,
      // 搜索栏配置项
      searchSittingArray:Object.assign([],this.getFieldArr()),
      listTableSitting:{
        modelName:'商品日志-列表',
        fieldArr:this.getFieldArr(),
        tableHeight:(this.$props.productData && this.$props.productData.id)?500:this.getTableHeight(),
        page:1,
        pageSize:20,
        actColumnWidth:-1,
        defaultSort:{
          // prop:'username',
          // order:'descending',
        }
      }
    }
  },
  methods:{
    getFieldArr:function () {
      return DemoData.ProductLog.field
    },
    getTableHeight:function () {
      var height=this.getWinSize().height-225
      return height>500?height:500
    },
    isDialogShow:function () {
      return this.$props.productData && this.$props.productData.id
    },
    // 初始化查询
    searchList:function () {
      // 表格列表,查询参数
      var listTableForm=this.$refs.myCommonListTable.formData

      // 搜索栏,查询参数
      var searchBarForm={}
      if (this.isDialogShow()){
        if (this.$props.productData && this.$props.productData.id){
          searchBarForm.supplierProductId=this.$props.productData.id
        }
      }else{
        searchBarForm=this.$refs.commonListSearchBar.getFormData()
      }

      var form=Object.assign({},listTableForm,searchBarForm)
      // 如果有默认排序 && 默认排序数据未设置,就进行查询请求(默认排序设置会触发查询)
      if (this.listTableSitting.defaultSort && this.listTableSitting.defaultSort.prop && this.$refs.myCommonListTable.formData.sortOrder===''){
        return ''
      }

      let $this=this
      $this.loading=true
      $this.MyRequest($this.ApiDoNameSupplier+'Product/getLogList',form,function (data) {
        $this.$refs.myCommonListTable.setListData(data)
        $this.loading=false
        $this.$forceUpdate()
      })
    },
  }
}
</script>

<style scoped>

</style>
